package com.itheima.health.controller;

import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.service.CheckItemService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("checkitem")
@PreAuthorize("hasAuthority('USER')")
public class CheckItemController {

    @Reference
    private CheckItemService checkItemService;

    @GetMapping("findAll")
    @PreAuthorize("hasAuthority('SELECT')")
    public Result findAll(){

        return new Result(true,"查询所有",checkItemService.listButZero());
    }

    @PostMapping("findAll")
    public Result findAll(@RequestBody QueryPageBean pageBean){
        PageResult page = checkItemService.findPage(pageBean);
        return new Result(true,"查询所有",page);
    }

    @PostMapping("add")
    public Result add(@RequestBody CheckItem checkItem){
        return new Result(true,"操作成功",checkItemService.saveOrUpdate(checkItem));
    }
    @DeleteMapping("deleteCheckItemById/{id}")
    public Result deleteCheckItemById(@PathVariable int id){
        CheckItem checkItem = new CheckItem();
        checkItem.setId(id);
        checkItem.setIs_delete(1);
        return new Result(true,"删除成功",checkItemService.updateById(checkItem));
    }

}
